// member/pages/memberCard/memberCard.js
let myRequest = require('../../../common/script/myRequest.js');
let api = require('../../../common/script/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: null,
    member_card: null,
    bindFlag: false,
    isfoundingmember: false,
  },
  // 获取用户信息
  getData() {
    const that = this;
    wx.showLoading({
      title: '加载中...',
    })
    myRequest.EasyHttp.post(api.reqUrls.userInfo).then(res => {
      wx.hideLoading();
      if (res.data.status == 1) {
        that.setData({
          userInfo: res.data.result
        })

      }
    })
  },
  //获取创世会员
  getCardinfoData() {
    const that = this;
    myRequest.EasyHttp.post(api.reqUrls.membercardShow).then(res => {
      if (res.data.status == 1) {
        that.setData({
          isfoundingmember: res.data.result.member_data.isfoundingmember,
        })
      }
    })
  },
  //会员卡信息
  getUserMember() {
    let that = this;
    let data = {
      encrypt_str: ''
    }
    myRequest.EasyHttp.post(api.reqUrls.getUserMemberInfo, data).then(res => {
      wx.hideLoading();
      if (res.data.status == 1) {
        that.setData({
          member_card: res.data.result.member_card,
          bindFlag: res.data.result.bindFlag,
        })
      } else {
        wx.showToast({
          title: res.data.msg,
          icon: 'error',
          duration: 2000
        })
      }
    })
  },
  //充值金额
  toTecharge() {
    const that = this;
    if (that.data.isnoshowCard) {
      wx.showToast({
        title: '请绑定会员卡',
        icon: 'error',
        duration: 2000
      })
      return
    }
    wx.navigateTo({
      url: `/member/pages/recharge/recharge`,
    })
  },
  //付款
  toPayment() {
    wx.switchTab({
      url: '/pages/index/index'
    })
  },
  //优惠券
  toCoupon() {
    wx.navigateTo({
      url: `/member/pages/coupon/coupon`,
    })
  },
  //充值记录
  toRechargeRecord() {
    wx.navigateTo({
      url: `/member/pages/rechargeRecord/rechargeRecord`,
    })
  },
  // 消费记录
  toSpending() {
    wx.navigateTo({
      url: `/member/pages/spending/spending`,
    })
  },

  //线下订单
  toOfflineOrder() {
    wx.navigateTo({
      url: `/member/pages/offlineOrder/offlineOrder`,
    })
  },
  // 会员卡详情
  toCardDetail() {
    wx.navigateTo({
      url: `/member/pages/cardDetail/cardDetail`,
    })
  },
  //更换会员卡
  toSwapCard() {
    wx.navigateTo({
      url: `/member/pages/swapCard/swapCard`,
    })
  },
  //云管家
  toButler() {
    wx.navigateTo({
      url: `/member/pages/butler/butler`,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const that = this;
    that.getUserMember()
    that.getData()
    that.getCardinfoData()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})